/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cbsnserverparte;

import java.security.*;

/**
 *
 * @author Craig Butler (5668670)
 * @author Stephen Norman (616000X)
 * @version 1.0 21/05/2008
 */
public class Util
{
    static String getTime()
    {
        // Create a new Calendar to return the current Date/Time
        java.util.Calendar cal = java.util.Calendar.getInstance();
        
        // Provide the time format in HH:mm:ss (13:07:14.564)
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("HH:mm:ss.S");
        
        // Return the date in the specified format (with the [] brackets)
        return "[" +  sdf.format(cal.getTime()) + "] ";
    }
    
    public static String hashPacket(byte[] packetData) 
    {
           String hashword = null;
           try 
           {
               MessageDigest md5 = MessageDigest.getInstance("MD5");
               md5.update(packetData);
               java.math.BigInteger hash = new java.math.BigInteger(1, md5.digest());
               hashword = hash.toString(16);
           } 
           catch (NoSuchAlgorithmException nsae) 
           {
                   // ignore
           }
           return hashword;
    }
}
